package com.jnks.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Ryo
 */

@AllArgsConstructor
public enum ShapeTypeEnum {

    /**
     * 通用状态枚举
     */
    ROUND(0, "圆形"),
    POLYGON(1, "多边形")
    ;

    @Getter
    @Setter
    private Integer code;
    @Getter
    @Setter
    private String message;

    public static ShapeTypeEnum getByCode(String code) {
        if (null == code) {
            return null;
        }

        for (ShapeTypeEnum shapeTypeEnum : ShapeTypeEnum.values()) {
            if (shapeTypeEnum.getCode().equals(code)) {
                return shapeTypeEnum;
            }
        }

        return null;
    }

    /**
     * 转化枚举为Map,key为code, value为message
     *
     * @return
     */
    public static Map<Integer, String> convert2Map() {
        Map<Integer, String> map = new HashMap<Integer, String>();
        for (ShapeTypeEnum shapeTypeEnum : ShapeTypeEnum.values()) {
            map.put(shapeTypeEnum.getCode(), shapeTypeEnum.getMessage());
        }
        return map;
    }

}
